home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1994 October / Macformat17.cdr / Shareware City / Developers / shutdown-fx-20-c / sfx control app ƒ / Shell ƒ / graphics.c < prev    next >
Text File  |  1994-07-11  |  17KB  |  534 lines

  1. /**********************************************************************\
  2.  
  3. File:        graphics.c
  4.  
  5. Purpose:    This module handles opening/closing/updating all windows:
  6.             this includes manipulating offscreen GWorlds & bitmaps
  7.             for fun and profit.
  8.  
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program in a file named "GNU General Public License".
  21. If not, write to the Free Software Foundation, 675 Mass Ave,
  22. Cambridge, MA 02139, USA.
  23.  
  24. \**********************************************************************/
  25.  
  26. #include "graphics.h"
  27. #include "about.h"
  28. #include "about MSG.h"
  29. #include "help.h"
  30. #include "dialogs.h"
  31. #include "error.h"
  32. #include "menus.h"
  33. #include "environment.h"
  34. #include "prefs.h"
  35. #include "util.h"
  36. #include "program globals.h"
  37.  
  38. /* internal global variables for use by graphics.c only */
  39. static    ExtendedWindowDataHandle    gTheWindowData[NUM_WINDOWS];
  40. static    Rect        gBoundsRect[NUM_WINDOWS];        /* rectangle of offscreen bitmap */
  41. static    Rect        gMainScreenBounds;                /* bounds of main monitor */
  42. static    GWorldPtr    gTheGWorld[NUM_WINDOWS];        /* offscreen graphics world */
  43. static    Ptr            gBWBitMap[NUM_WINDOWS];            /* offscreen bitmap for B/W machines */
  44. static    GrafPort    gBWGrafPort[NUM_WINDOWS];        /* offscreen grafport "  "     "     */
  45. static    GrafPtr        gBWGrafPtr[NUM_WINDOWS];        /* offscreen grafptr  "  "     "     */
  46. static    GWorldPtr    currentGWorld;
  47. static    GDHandle    currentGDHandle;
  48.  
  49. Boolean InitTheGraphics(void)
  50. {
  51.     short            i,j;
  52.     
  53.     GetMainScreenBounds();
  54.     
  55.     for (i=0; i<NUM_WINDOWS; i++)
  56.     {
  57.         /* nothing is inited; if there's an error later on, we'll know how much to */
  58.         /* clean up in ShutDownTheGraphics() */
  59.         gTheGWorld[i]=(GWorldPtr)0L;
  60.         gTheWindowData[i]=(ExtendedWindowDataHandle)0L;
  61.     }
  62.     
  63.     for (i=0; i<NUM_WINDOWS; i++)
  64.     {
  65.         gTheWindowData[i]=(ExtendedWindowDataHandle)NewHandle(sizeof(ExtendedWindowDataRec));
  66.         if (gTheWindowData[i]==0L)                            /* return if error */
  67.             return FALSE;
  68.         
  69.         (**(gTheWindowData[i])).offscreenNeedsUpdate=TRUE;    /* offscreen not inited */
  70.         (**(gTheWindowData[i])).theWindowPtr=0L;            /* window ptr not inited */
  71.         (**(gTheWindowData[i])).windowIndex=i;                /* so we can retrieve it O(1) */
  72.         (**(gTheWindowData[i])).windowDepth=
  73.             (**(gTheWindowData[i])).maxDepth=1;                /* init at B/W */
  74.         (**(gTheWindowData[i])).isColor=FALSE;                /* init to grayscale */
  75.         for (j=0; j<MAX_TE_HANDLES; j++)
  76.             (**(gTheWindowData[i])).hTE[j]=0L;
  77.         HLockHi((Handle)gTheWindowData[i]);
  78.     }
  79.     
  80.     /* set window dispatch routines */
  81.     SetIndDispatchProc(kAbout, AboutBoxDispatch);
  82.     SetIndDispatchProc(kHelp, HelpWindowDispatch);
  83.     SetIndDispatchProc(kAboutMSG, AboutMSGBoxDispatch);
  84.     
  85.     /* call window dispatch routines with "startup" message */
  86.     CallIndDispatchProc(kAbout, kStartup, 0L);
  87.     CallIndDispatchProc(kHelp, kStartup, 0L);
  88.     CallIndDispatchProc(kAboutMSG, kStartup, 0L);
  89.     
  90.     return TRUE;
  91. }
  92.  
  93. void OpenTheIndWindow(short index)
  94. {
  95.     WindowPtr        theWindow;
  96.     
  97.     if (!((**gTheWindowData[index]).theWindowPtr))        /* if window exists, we'll just update it (see below) */
  98.     {
  99.         if (CallIndDispatchProc(index, kInitialize, 0L)==kFailure)
  100.         {        /* default is to center window on main screen */
  101.             (**(gTheWindowData[index])).initialTopLeft.h =
  102.                 gMainScreenBounds.left + (((gMainScreenBounds.right -
  103.                 gMainScreenBounds.left) - (**(gTheWindowData[index])).windowWidth) / 2);
  104.             (**(gTheWindowData[index])).initialTopLeft.v =
  105.                 gMainScreenBounds.top + (((gMainScreenBounds.bottom -
  106.                 gMainScreenBounds.top) - (**(gTheWindowData[index])).windowHeight) / 2);
  107.         }
  108.         
  109.         (**(gTheWindowData[index])).windowBounds.left=
  110.             (**(gTheWindowData[index])).initialTopLeft.h;
  111.         
  112.         (**(gTheWindowData[index])).windowBounds.top=
  113.             (**(gTheWindowData[index])).initialTopLeft.v;
  114.             
  115.         if (((**(gTheWindowData[index])).windowType==noGrowDocProc) ||
  116.             ((**(gTheWindowData[index])).windowType==documentProc) ||
  117.             ((**(gTheWindowData[index])).windowType==movableDBoxProc) ||
  118.             ((**(gTheWindowData[index])).windowType==zoomDocProc) ||
  119.             ((**(gTheWindowData[index])).windowType==zoomNoGrow) ||
  120.             ((**(gTheWindowData[index])).windowType==rDocProc))
  121.                 (**(gTheWindowData[index])).windowBounds.top += 9;    /* compensate for title */
  122.         
  123.         /* don't put window over menu bar */
  124.         if ((**(gTheWindowData[index])).windowBounds.top < GetMBarHeight()+1)
  125.             (**(gTheWindowData[index])).windowBounds.top = GetMBarHeight()+1;
  126.         
  127.         (**(gTheWindowData[index])).windowBounds.bottom =
  128.             (**(gTheWindowData[index])).windowBounds.top +
  129.             (**(gTheWindowData[index])).windowHeight;
  130.         
  131.         (**(gTheWindowData[index])).windowBounds.right =
  132.             (**(gTheWindowData[index])).windowBounds.left +
  133.             (**(gTheWindowData[index])).windowWidth;
  134.         
  135.         KillOffscreen(index);        /* kill offscreen bitmaps that are left over */
  136.         
  137.         if (gHasColorQD)
  138.         {
  139.             /* create the color window with our specs, see IM Essentials 4-79ff */
  140.             (**gTheWindowData[index]).theWindowPtr=
  141.                 NewCWindow(0L, &((**(gTheWindowData[index])).windowBounds),
  142.                 (**(gTheWindowData[index])).windowTitle, FALSE,
  143.                 (**(gTheWindowData[index])).windowType, (WindowPtr)-1L,
  144.                 (**(gTheWindowData[index])).hasCloseBox,
  145.                 (unsigned long)gTheWindowData[index]);
  146.         }
  147.         else
  148.         {
  149.             /* create the B/W window with our specs, see IM Essentials 4-82ff */
  150.             (**gTheWindowData[index]).theWindowPtr=
  151.                 NewWindow(0L, &((**(gTheWindowData[index])).windowBounds),
  152.                 (**(gTheWindowData[index])).windowTitle, FALSE,
  153.                 (**(gTheWindowData[index])).windowType, (WindowPtr)-1L,
  154.                 (**(gTheWindowData[index])).hasCloseBox,
  155.                 (unsigned long)gTheWindowData[index]);
  156.         }
  157.     }
  158.     
  159.     if ((theWindow=GetIndWindowGrafPtr(index))!=0L)
  160.     {
  161.         SetPort(theWindow);            /* important! for TE info to stick*/
  162.         /* call window's dispatch routine to alert it that it's open now */
  163.         CallIndDispatchProc(index, kOpen, 0L);
  164.         ShowWindow(theWindow);            /* immediately show this new window */
  165.         SelectWindow(theWindow);        /* immediately select this new window */
  166.     }
  167.     else
  168.     {
  169.         SetErrorParameters("\pOperation: open window", "\p", "\p");
  170.         HandleError(kNoMemory, FALSE, TRUE);            /* if unsuccessful, display error */
  171.     }
  172. }
  173.  
  174. void OpenTheWindow(ExtendedWindowDataHandle theData)
  175. {
  176.     OpenTheIndWindow((**theData).windowIndex);
  177. }
  178.  
  179. void GetMainScreenBounds(void)
  180. {
  181.     gMainScreenBounds = screenBits.bounds;        /* low-mem global */
  182.     gMainScreenBounds.top += GetMBarHeight();    /* don't include menu bar */
  183. }
  184.  
  185. short GetBiggestDeviceDepth(WindowDataHandle theData)
  186. {
  187.     short            index;
  188.     Rect            tempRect;
  189.     long            biggestSize;
  190.     long            tempSize;
  191.     GDHandle        thisHandle, gBiggestDevice;
  192.     
  193.     if (!gHasColorQD)
  194.         return 1;
  195.     
  196.     index=(**theData).windowIndex;
  197.     
  198.     if (!GetIndWindowGrafPtr(index))
  199.         return (**(**GetMainDevice()).gdPMap).pixelSize;
  200.     
  201.     thisHandle = GetDeviceList();
  202.     gBiggestDevice = 0L;
  203.     biggestSize = 0L;
  204.     
  205.     while (thisHandle)
  206.     {
  207.         if (TestDeviceAttribute(thisHandle, screenDevice) &&
  208.             TestDeviceAttribute(thisHandle, screenActive))
  209.         {
  210.             if (SectRect(&(GetIndWindowGrafPtr(index)->portRect), &((**thisHandle).gdRect),
  211.                     &tempRect))
  212.             {
  213.                 if (biggestSize < (tempSize = ((long)(tempRect.bottom - tempRect.top))*
  214.                     ((long)(tempRect.right - tempRect.left))))
  215.                 {
  216.                     biggestSize = tempSize;
  217.                     gBiggestDevice = thisHandle;
  218.                 }
  219.             }
  220.         }
  221.         thisHandle = GetNextDevice(thisHandle);
  222.     }
  223.     
  224.     return (gBiggestDevice) ? (**(**gBiggestDevice).gdPMap).pixelSize : 1;
  225. }
  226.  
  227. short GetWindowDepth(WindowDataHandle theData)
  228. {
  229.     short            index;
  230.     
  231.     index=(**theData).windowIndex;
  232.     /* if Color Quickdraw is not available, the depth must be 1. */
  233.     /* if Color Quickdraw is available and the window exists, return the window's
  234.        GWorld's graphics device's pixel map's pixel depth */
  235.     /* if Color Quickdraw is available and the window does not exist, return the
  236.        pixel depth of the main screen */
  237.     return (gHasColorQD) ? ((GetIndWindowGrafPtr(index)) ?
  238.             (**(**(GetGWorldDevice(gTheGWorld[index]))).gdPMap).pixelSize :
  239.             (**(**GetMainDevice()).gdPMap).pixelSize) : 1;
  240. }
  241.  
  242. Boolean WindowIsColor(WindowDataHandle theData)
  243. {
  244.     short            index;
  245.     
  246.     index=(**theData).windowIndex;
  247.     return (gHasColorQD) ? ((GetWindowDepth(theData)>8) ? TRUE :
  248.         TestDeviceAttribute(GetGWorldDevice(gTheGWorld[index]), gdDevType)) : FALSE;
  249. }
  250.  
  251. void ForceUpdateTheIndWindow(short index)
  252. {
  253.     (**(gTheWindowData[index])).offscreenNeedsUpdate=TRUE;
  254.     UpdateTheWindow(gTheWindowData[index]);
  255. }
  256.  
  257. void UpdateTheWindow(ExtendedWindowDataHandle theData)
  258. {
  259.     short            index;
  260.     long            offRowBytes, sizeOfOff;
  261.     unsigned long    updateResult;
  262.     Boolean            isColor;
  263.     PixMapHandle    thePixMapHandle;
  264.     
  265.     index=(**theData).windowIndex;
  266.     gBoundsRect[index]=GetIndWindowGrafPtr(index)->portRect;
  267.     OffsetRect(&gBoundsRect[index], -gBoundsRect[index].left, -gBoundsRect[index].top);
  268.  
  269.     if (gHasColorQD)    /* w/o Color Quickdraw, GWorlds may not be supported */
  270.     {
  271.         if (gTheGWorld[index]==0L)        /* create new graphics world if none exists */
  272.         {
  273.             /* try to create new graphics world; display error if unsuccessful */
  274.             if (NewGWorld(&gTheGWorld[index],
  275.                 (GetBiggestDeviceDepth(theData)>=(**theData).maxDepth) ?
  276.                 (**theData).maxDepth : 0, &gBoundsRect[index], 0L, 0L, 0)!=0)
  277.             {
  278.                 SetErrorParameters("\pOperation: update window", "\p", "\p");
  279.                 HandleError(kNoMemory, TRUE, TRUE);        /* quits */
  280.             }
  281.             
  282.             (**theData).windowDepth=GetWindowDepth((WindowDataHandle)theData);
  283.             NoPurgePixels(GetGWorldPixMap(gTheGWorld[index]));    /* never purge our pixmap! */
  284.             updateResult=1;
  285.         }
  286.         else updateResult=0;
  287.         
  288.         GetGWorld(¤tGWorld, ¤tGDHandle);    /* get current settings */
  289.         LockPixels(thePixMapHandle=GetGWorldPixMap(gTheGWorld[index]));    /* important!  copybits may move mem */
  290.         /* update offscreen graphics world, compensating for change in pixel depth */
  291.         updateResult|=(unsigned long)UpdateGWorld(&gTheGWorld[index],
  292.             (GetBiggestDeviceDepth(theData)>=(**theData).maxDepth) ? (**theData).maxDepth :
  293.             0, &gBoundsRect[index], 0L, 0L, 0);
  294.         SetGWorld(gTheGWorld[index], 0L);                /* set to our offscreen gworld */
  295.         
  296.         isColor=WindowIsColor(theData);
  297.         if (isColor!=(**theData).isColor)
  298.         {
  299.             (**theData).isColor=isColor;
  300.             updateResult=1;
  301.         }
  302.         
  303.         if ((updateResult!=0L) || ((**theData).windowDepth!=GetWindowDepth(theData)))
  304.         {
  305.             (**theData).windowDepth=GetWindowDepth((WindowDataHandle)theData);    /* save new depth */
  306.             (**theData).offscreenNeedsUpdate=TRUE;                /* we'll need to redraw */
  307.             CallDispatchProc(theData, kChangeDepth, 0L);
  308.         }
  309.     }
  310.     else    /* deal with (guaranteed) B/W bitmaps manually */
  311.     {
  312.         if (gBWGrafPtr[index]==0L)    /* create new offscreen bitmap if none exists */
  313.         {
  314.             gBWGrafPtr[index]=&gBWGrafPort[index];
  315.             OpenPort(gBWGrafPtr[index]);    /* make a new port */
  316.             
  317.             /* calculate the size of the offscreen bitmap from the boundsrect */
  318.             offRowBytes=(((gBoundsRect[index].right-gBoundsRect[index].left)+15)>>4)<<1;
  319.             sizeOfOff=(long)(gBoundsRect[index].bottom-gBoundsRect[index].top)*offRowBytes;
  320.             
  321.             gBWBitMap[index]=NewPtr(sizeOfOff);        /* allocate space for bitmap */
  322.             if (gBWBitMap[index]==0L)                /* abort if unsuccessful */
  323.             {
  324.                 ClosePort(gBWGrafPtr[index]);        /* cleaning up... */
  325.                 gBWGrafPtr[index]=0L;
  326.                 SetErrorParameters("\pOperation: update window", "\p", "\p");
  327.                 HandleError(kNoMemory, TRUE, TRUE);        /* displaying error... */
  328.             }
  329.             
  330.             gBWGrafPort[index].portBits.baseAddr=gBWBitMap[index];    /* --> our bitmap */
  331.             gBWGrafPort[index].portBits.rowBytes=offRowBytes;        /* bitmap size */
  332.             gBWGrafPort[index].portBits.bounds=                        /* bitmap bounds */
  333.                 gBWGrafPort[index].portRect=gBoundsRect[index];
  334.             
  335.             SetPort(gBWGrafPtr[index]);
  336.             (**theData).offscreenNeedsUpdate=TRUE;
  337.         }
  338.         else SetPort(gBWGrafPtr[index]);            /* set port for subsequent drawing */
  339.     }    
  340.     
  341.     if ((**theData).offscreenNeedsUpdate)            /* if we need to redraw */
  342.     {
  343.         (**theData).offscreenNeedsUpdate=FALSE;        /* not anymore */
  344.         /* call window's dispatch and tell it to redraw itself */
  345.         CallDispatchProc(theData, kUpdate, GetWindowDepth((WindowDataHandle)theData));
  346.     }
  347.     
  348.     if (gHasColorQD)
  349.         SetGWorld(currentGWorld, currentGDHandle);    /* restore old settings */
  350.     
  351.     SetPort(GetWindowGrafPtr(theData));
  352.     
  353.     /* copy offscreen bitmap from graphics world or bitmap to onscreen window */
  354.     if (CallDispatchProc(theData, kCopybits, gHasColorQD ? (unsigned long)gTheGWorld[index] :
  355.         (unsigned long)gBWGrafPtr[index])==kFailure)
  356.         CopyBits(gHasColorQD ? &(((GrafPtr)gTheGWorld[index])->portBits) :
  357.                     &(gBWGrafPtr[index]->portBits), &(GetIndWindowGrafPtr(index)->portBits),
  358.                     &gBoundsRect[index], &gBoundsRect[index], 0, 0L);
  359.     
  360.     for (index=0; index<MAX_TE_HANDLES; index++)
  361.     {
  362.         if ((**theData).hTE[index]!=0L)
  363.             TEUpdate(&(GetIndWindowGrafPtr(index)->portRect), (**theData).hTE[index]);
  364.     }
  365.  
  366.     ValidRect(&(GetIndWindowGrafPtr(index)->portRect));        /* so we don't reupdate */
  367.     
  368.     if (gHasColorQD)
  369.         UnlockPixels(thePixMapHandle);    /* remember we locked these? */
  370. }
  371.  
  372. Boolean CloseTheWindow(ExtendedWindowDataHandle theData)
  373. {
  374.     short            index;
  375.     
  376.     index=(**theData).windowIndex;
  377.     
  378.     /* if the window's dispatch cancels the close, abort */
  379.     if (CallDispatchProc((WindowDataHandle)theData, kClose, 0L)==kCancel)
  380.         return FALSE;
  381.     
  382.     DisposeWindow(GetIndWindowGrafPtr(index));    /* get rid of the actual window in memory */
  383.     (**gTheWindowData[index]).theWindowPtr=0L;    /* so _we_ know the window doesn't exist */
  384.     KillOffscreen(index);                /* kill offscreen bitmaps left over */
  385.     
  386.     /* tell window's dispatch that it's disposed of now */
  387.     CallDispatchProc((WindowDataHandle)theData, kDispose, 0L);
  388.     
  389.     return TRUE;    /* successful close */
  390. }
  391.  
  392. Boolean CloseTheIndWindow(short index)
  393. {
  394.     return CloseTheWindow(gTheWindowData[index]);
  395. }
  396.  
  397. PicHandle DrawThePicture(PicHandle thePict, short whichPict, short x, short y)
  398. /* a standard routine for loading a picture (if necessary) and then drawing it */
  399. {
  400.     Rect            temp;
  401.     
  402.     if (thePict==0L)        /* get it if it doesn't exist */
  403.         thePict=(PicHandle)GetPicture(whichPict);
  404.     
  405.     HLock((Handle)thePict);        /* lock it down for dereferencing to get picture bounds */
  406.     temp.top=y;
  407.     temp.left=x;
  408.     temp.bottom=temp.top+(**thePict).picFrame.bottom-(**thePict).picFrame.top;
  409.     temp.right=temp.left+(**thePict).picFrame.right-(**thePict).picFrame.left;
  410.     DrawPicture(thePict, &temp);    /* draw picture at (x,y) */
  411.     HUnlock((Handle)thePict);        /* unlock for better memory management */
  412.     return thePict;
  413. }
  414.  
  415. PicHandle ReleaseThePict(PicHandle thePict)
  416. {
  417.     if (thePict!=0L)    /* if exists, release it */
  418.         ReleaseResource((Handle)thePict);
  419.     return 0L;
  420. }
  421.  
  422. Boolean SetPortToOffscreen(WindowDataHandle theData)
  423. {
  424.     short            index;
  425.     
  426.     index=(**theData).windowIndex;
  427.     
  428.     if (gHasColorQD)
  429.     {
  430.         if (gTheGWorld[index]==0L)
  431.             return FALSE;
  432.         GetGWorld(¤tGWorld, ¤tGDHandle);    /* get current settings */
  433.         LockPixels(GetGWorldPixMap(gTheGWorld[index]));    /* important!  copybits may move mem */
  434.         SetGWorld(gTheGWorld[index], 0L);
  435.     }
  436.     else
  437.     {
  438.         if (gBWGrafPtr[index]==0L)
  439.             return FALSE;
  440.         SetPort(gBWGrafPtr[index]);
  441.     }
  442.     
  443.     return TRUE;
  444. }
  445.  
  446. void RestorePortToScreen(WindowDataHandle theData)
  447. {
  448.     if (gHasColorQD)
  449.     {
  450.         SetGWorld(currentGWorld, currentGDHandle);    /* restore old settings */
  451.         UnlockPixels(GetGWorldPixMap(gTheGWorld[(**theData).windowIndex]));
  452.     }
  453.     
  454.     SetPort(GetWindowGrafPtr(theData));
  455. }
  456.  
  457. GrafPtr GetOffscreenGrafPtr(WindowDataHandle theData)
  458. {
  459.     if (gHasColorQD)
  460.         return (GrafPtr)gTheGWorld[(**theData).windowIndex];
  461.     else
  462.         return gBWGrafPtr[(**theData).windowIndex];
  463. }
  464.  
  465. GrafPtr GetIndOffscreenGrafPtr(short index)
  466. {
  467.     return GetOffscreenGrafPtr(gTheWindowData[index]);
  468. }
  469.  
  470. GrafPtr GetWindowGrafPtr(WindowDataHandle theData)
  471. {
  472.     return (GrafPtr)((**theData).theWindowPtr);
  473. }
  474.  
  475. GrafPtr GetIndWindowGrafPtr(short index)
  476. {
  477.     return GetWindowGrafPtr(gTheWindowData[index]);
  478. }
  479.  
  480. WindowDataHandle GetIndWindowDataHandle(short index)
  481. {
  482.     return gTheWindowData[index];
  483. }
  484.  
  485. void SetIndDispatchProc(short index, ProcPtr theProc)
  486. {
  487.     (**gTheWindowData[index]).dispatchProc=theProc;
  488. }
  489.  
  490. short CallIndDispatchProc(short index, short theMessage, unsigned long misc)
  491. {
  492.     return ((**(gTheWindowData[index])).dispatchProc)((WindowDataHandle)gTheWindowData[index], theMessage, misc);
  493. }
  494.  
  495. short CallDispatchProc(ExtendedWindowDataHandle theData, short theMessage, unsigned long misc)
  496. {
  497.     return ((**theData).dispatchProc)((WindowDataHandle)theData, theMessage, misc);
  498. }
  499.  
  500. void SetIndWindowTitle(short index, Str255 theTitle)
  501. {
  502.     Mymemcpy((Ptr)((**(gTheWindowData[index])).windowTitle), (Ptr)theTitle, theTitle[0]+1);
  503. }
  504.  
  505. void KillOffscreen(short index)
  506. {
  507.     if (gTheGWorld[index]!=0L)
  508.         DisposeGWorld(gTheGWorld[index]);
  509.     if (gBWGrafPtr[index]!=0L)
  510.         DisposePtr((Ptr)gBWGrafPtr[index]);
  511.     gTheGWorld[index]=0L;
  512.     gBWGrafPtr[index]=0L;
  513.     (**(gTheWindowData[index])).offscreenNeedsUpdate=TRUE;
  514. }
  515.  
  516. void ShutDownTheGraphics(void)
  517. {
  518.     short            i;
  519.     
  520.     /* send shutdown messages to the shell's windows */
  521.     CallIndDispatchProc(kAbout, kShutdown, 0L);
  522.     CallIndDispatchProc(kHelp, kShutdown, 0L);
  523.     CallIndDispatchProc(kAboutMSG, kShutdown, 0L);
  524.     
  525.     for (i=0; i<NUM_WINDOWS; i++)
  526.     {
  527.         KillOffscreen(i);
  528.         if (GetIndWindowGrafPtr(i)!=0L)
  529.             DisposeWindow((**gTheWindowData[i]).theWindowPtr);
  530.         if (gTheWindowData[i]!=0L)
  531.             DisposeHandle((Handle)gTheWindowData[i]);
  532.     }
  533. }
  534.